import { timeoutTask } from '@/utils/index';

const state = {
  loadingVisible: true,
  useTipVisible: false,
  currentLoadingProgress: 0,
  popupAreaVisible: false,
  popupModuleKey: -1,
  token: '',
  chatAreaScrollId: '',
  previewImg: '', // 预览图片地址
  currentGiftType: '', // 当前选中的礼物类型(giftId)
  currentPhotoType: '', // 当前选中的照片类型(giftId)
  currentDanmuType: '', // 当前选中的霸气弹幕类型(giftId)
  currentBapinType: '', // 当前选中的霸屏类型(giftId)
  currentSuperDanmuType: '', // 当前选中的超级弹幕类型(giftId)
  currentTipGiftType: '', // 打赏弹窗中当前选中的礼物类型(giftId)
  gameBtnVisible: false, // 游戏按钮出现与隐藏
  origin: '', // 设置进入场景 用于h5跳转小程序再返回的场景记忆(sendGift、sendBapin、sendPhoto、sendDanmu、sendRecommendGift)
  rcGiftGameCodes: [], // 每个游戏结束后只出现一次推荐礼物 并保存出现过的gameCode
  atText: '', // 推荐礼物的文字
  bapinCloseIconVisible: false, // 是否展示霸屏关闭按钮
  isCloseCurrentBapin: false, // 是否关闭当前霸屏
  giftSendVisible: false, // 礼物发送是否可见(礼物、霸屏、照片、霸气弹幕)
  hbkdVisible: false, // 红包口袋带是否可见
  photographerVisible: false, // 摄影师照片墙是否可见
  photographerImgPrice: 0, // 摄影师照片墙照片价格
  needLogin: false,
  heartWallPrice: '0',
  editUserInfoPrice: '0',
  chooseSongVisible: false, // 点歌功能是否可见
  musicMode: '0', // '0'为普通模式, '1'为歌手模式
  songSheetList: [], // 歌单列表
  songOrderList: [], // 已点歌曲列表
  singerList: [], // 歌手列表
  currentSingerId: '', // 当前选中的歌手ID，空字符串代表"全部"
  currentTipSingerId: '', // 打赏组件中当前选中的歌手ID
  tipGiftList: [], // 打赏礼物列表
  tipDeskNum: '', // 打赏选中的桌号（字符串）
  canCustomizeInput: true,
};

const mutations = {
  setNeedLogin: (state, data) => {
    state.needLogin = data;
  },
  setLoading: (state, data) => {
    state.loadingVisible = data;
  },
  updateCurrentLoadingProgress: (state, data) => {
    state.currentLoadingProgress = `${data}%`;
  },
  setToken: (state, data) => {
    state.token = data;
  },
  togglePopup: (state, data) => {
    if (!state.popupAreaVisible) {
      state.popupAreaVisible = true;
      timeoutTask(() => {
        state.popupModuleKey = data;
        console.log('***popupModuleKey***');
        console.log(state.popupModuleKey);
      }, 100);
    } else {
      // If data is provided and is different from the current key, switch modules.
      // Otherwise, close the popup.
      if (data !== undefined && data !== state.popupModuleKey) {
        state.popupModuleKey = data;
        return;
      }
      state.popupModuleKey = -1;
      timeoutTask(() => {
        state.popupAreaVisible = false;
      }, 200);
    }
  },
  setChatAreaScrollId: (state, data) => {
    state.chatAreaScrollId = data;
  },
  setPreviewImg: (state, data) => {
    state.previewImg = data;
  },
  resetPreviewImg: (state) => {
    state.previewImg = '';
  },
  setCurrentGiftType: (state, data) => {
    state.currentGiftType = data;
  },
  setCurrentPhotoType: (state, data) => {
    state.currentPhotoType = data;
  },
  setCurrentDanmuType: (state, data) => {
    state.currentDanmuType = data;
  },
  setCurrentBapinType: (state, data) => {
    state.currentBapinType = data;
  },
  setCurrentSuperDanmuType: (state, data) => {
    state.currentSuperDanmuType = data;
  },
  setCurrentTipGiftType: (state, data) => {
    state.currentTipGiftType = data;
  },
  setGameBtnVisible: (state, data) => {
    state.gameBtnVisible = data;
  },
  setOrigin: (state, data) => {
    state.origin = data;
  },
  setUseTip: (state, data) => {
    state.useTipVisible = data;
  },
  updateRcGiftGameCodes: (state, data) => {
    state.rcGiftGameCodes.push(data);
    state.atText = '游戏结束啦送个祝福吧!';
  },
  setIsCloseCurrentBapin: (state, data) => {
    state.isCloseCurrentBapin = data;
  },
  setBapinCloseIconVisible: (state, data) => {
    state.bapinCloseIconVisible = data;
  },
  setGiftSendVisible: (state, data) => {
    if (data === '0' || !data) {
      state.giftSendVisible = true;
    } else {
      state.giftSendVisible = false;
    }
  },
  setHbkdVisible: (state, data) => {
    if (data === '0' || !data) {
      state.hbkdVisible = true;
    } else {
      state.hbkdVisible = false;
    }
  },
  setHeartWallPrice: (state, data) => {
    state.heartWallPrice = data;
  },
  setEditUserInfoPrice: (state, data) => {
    state.editUserInfoPrice = data;
  },
  setPhotographerWallInfo: (state, data) => {
    state.photographerVisible = data.photo_shi_switch === '1';
    state.photographerImgPrice = parseFloat(data.photo_one_price);
  },
  setChooseSongVisible: (state, data) => {
    state.chooseSongVisible = data === '1';
  },
  setMusicMode: (state, mode) => {
    state.musicMode = mode;
  },
  setSongSheetList: (state, data) => {
    state.songSheetList = data.map((item) => {
      return {
        id: item.id,
        times: item.times,
        name: item.title,
        price: item.money,
      };
    });
  },
  setSongOrderList: (state, data) => {
    state.songOrderList = data.map((item) => {
      return {
        name: item.title,
        avator: item.avator,
        wxName: item.wx_name,
      };
    });
  },
  setSingerList: (state, data) => {
    state.singerList = data;
  },
  setCurrentSingerId: (state, data) => {
    state.currentSingerId = data;
  },
  setCurrentTipSingerId: (state, data) => {
    state.currentTipSingerId = data;
  },
  setTipGiftList: (state, data) => {
    state.tipGiftList = data;
  },
  setTipDeskNum: (state, data) => {
    state.tipDeskNum = data;
  },
  setCanCustomizeInput: (state, data) => {
    state.canCustomizeInput = data;
  },
};

const actions = {
  //   toggleSideBar({ commit }) {
  //     commit('TOGGLE_SIDEBAR')
  //   },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
